package com.example.demo.service.impl;


import com.example.demo.core.model.AuthUser;
import com.example.demo.entity.User;
import com.example.demo.service.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import java.util.Collections;

/**
 * @author yj
 * @date 2021-07-24 22:14
 */
@Slf4j
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userService.getByUsername(username);
        return new AuthUser(user.getPhone(), user.getPassword(), Collections.EMPTY_SET);
    }
}
